package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.market.Keyword;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.market.KeywordCreateVo;
import com.cskaoyan.bean.market.KeywordListBean;
import com.cskaoyan.bean.market.KeywordListVo;
import com.cskaoyan.service.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 商场管理模块 关键词单元
 * 赵维虎
 */
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @GetMapping("list")
    public BaseRespVo list(BaseParam baseParam,String keyword,String url) {
        KeywordListVo keywordListVo = keywordService.list(baseParam,keyword,url);
        return BaseRespVo.ok(keywordListVo);
    }


    @PostMapping("create")
    public BaseRespVo create(@RequestBody Map map){
        KeywordCreateVo keywordCreateVo = keywordService.create(map);
        if(keywordCreateVo == null){
            return  BaseRespVo.fail("已有该关键词，不能创建同名关键词");
        }
        return BaseRespVo.ok(keywordCreateVo);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody KeywordListBean keywordDeleteBo){
        keywordService.delete(keywordDeleteBo);
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody Keyword keyword){
        Keyword keyword1 = keywordService.update(keyword);
        return BaseRespVo.ok(keyword1);
    }
}
